package net.cloudsun.graph.puzzle.group;

import net.cloudsun.graph.puzzle.JigsawState;

/**
 * 创建群
 * created at 23/11/2021
 *
 * @author 俞建波
 * <a href="mailto://yujianbo@chtwm.com">yujianbo@chtwm.com</a>
 * @since 1.1.0
 */
public class PuzzleVerticalRollGroupBuilder extends AbstractPuzzleGroupBuilder<PuzzleVerticalRollGroup> {

    private int centerNumber;

    public PuzzleVerticalRollGroupBuilder(int centerNumber) {
        this.centerNumber = centerNumber;
    }


    @Override
    protected boolean check(String line) {
        // 0 1 2
        // 3 4 5
        // 6 7 8
        final char c1 = line.charAt(1);
        final char c2 = line.charAt(4);
        final char c3 = line.charAt(7);

        return Integer.parseInt(String.valueOf(c1)) == centerNumber
                || Integer.parseInt(String.valueOf(c2)) == centerNumber
                || Integer.parseInt(String.valueOf(c3)) == centerNumber;
    }



    @Override
    protected PuzzleVerticalRollGroup newGroup(JigsawState element) {
        return new PuzzleVerticalRollGroup();
    }
}
